package cn.edu.neu.vmmigeval.evaluation;


import cn.edu.neu.vmmigeval.cloud.entity.DataCenter;
import cn.edu.neu.vmmigeval.cloud.entity.DataCenterBroker;
import cn.edu.neu.vmmigeval.io.WriteUtil;

import java.util.List;

public class PDM {


    //totalEnergy  总能耗
    //slaas        SLA违反总数
    //costs        虚拟机迁移带来的影响

    public static void writePDMtoFile(double totalEnergy, String url, DataCenterBroker br, DataCenter dc, List<Integer> pdh, List<Double> pdv) {

        System.out.println("pdh is :" + pdh.size() + " pdv is :" + pdv.size());
        String url1 = url + "pdm.txt";
        String str = "";
        int size = dc.getHosts().size();
        int totalSLA = 0;
        double totalCosts = 0.0;
        for (Integer aPdh : pdh) {
            totalSLA += aPdh;
        }
        for (Double aPdv : pdv) {
            totalCosts += aPdv;
        }
        double finalSLA = 0.0, finalCost = 0.0;
        finalSLA = (double) totalSLA / size;
        finalCost = (double) totalCosts / br.getVms().size();

        double pdm = finalSLA * finalCost;
        str += "\r\n迁移个数:" + dc.getMigrationFinished().size() +
                "\t总的sla违反:" + finalSLA + "\t总的cost:" + finalCost + "\t总的PDM:" + pdm + "\t总的能耗: " + totalEnergy + "\t\r\n FOM: " + (totalEnergy * pdm);

        try {
            WriteUtil.writePDMToFile(url1, str);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

